Global Scripts in TGML Graphics
By default, each Script element (script block) creates a JavaScript context. In this mode, function calls between script blocks (contexts) are not supported, that is, no support for global script functions.
It is possible to enable scripts to run in one single context for the whole graphic so that functions and variables can be shared between script blocks. This is done by setting the TGML element property ‘UseGlobalScripts’ in the Graphics Editor to ‘True’. By default, 'UseGlobalScripts' is ‘False’.
Using ‘UseGlobalScripts’ may have a very positive effect on graphics loading performance in some of the viewers, such as the HTML5-based viewer in Diagrams.
Global variables
In the HTML5 viewer some names are reserved for the Web Browser. It might not be apparent for users writing Java Scripts that using reserved names can cause a conflict when viewing the TGML graphic in the HTML5 viewer, as it works fine in the Diagrams viewer.
You can check whether or not there is a conflict by using the Global Variables tool in the Graphics Editor Statistics pane to analyze the scripts in the TGML graphic and look for global variables that could cause name conflicts.
Example:
A script that contains a variable named ‘window’ without the var declaration might have been intended to be used as a local variable. However, not declaring it as ‘var’ makes it a global variable and since ‘window’ is a reserved word (an object in the Web Browser) this object is referenced instead, when the Web Browser executes the script.
function load(evt)
{
window = 1;
}
NOTE: The variable 'window' is visible in the list of Global script variables. To use reserved words locally in scripts as variables, make sure to declare them as ‘var’.
function load(evt)
{
var window = 1;
}